package com.woniuxy.ui;

import java.io.*;

/**
 * @author 作者
 * @create 2025-06-12 9:34
 */
public class Test01 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        save();
        load();
    }

    private static void load() throws IOException, ClassNotFoundException {
        ObjectInputStream ois =
                new ObjectInputStream(new FileInputStream("stu.bin"));
        Stu stu = (Stu) ois.readObject();
        ois.close();
        System.out.println(stu);
    }
    private static void save() throws IOException {
        ObjectOutputStream oos =
                new ObjectOutputStream(new FileOutputStream("stu.bin"));
        Stu stu=new Stu("1","zs",11,"male","");
        //底层使用二进制格式序列化保存数据
        oos.writeObject(stu);
        oos.close();
    }
}
